package org.xdq.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xdq.demo.base.PageParam;
import org.xdq.demo.dao.TestDao;
import org.xdq.demo.model.Employee;
import org.xdq.demo.service.TestService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service @Transactional
public class TestServiceImpl implements TestService {

    @Autowired
    private TestDao testDao;

    @Override
    public List<Employee> getEmpList() {
        return testDao.findEmpList();
    }

    @Override
    public Map<String, Object> getEmpPage(PageParam pageParam) {
        PageHelper.startPage(pageParam);
        List<Employee> list = testDao.findEmpList();
        PageInfo page = new PageInfo(list);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("total",page.getTotal());
        map.put("rows",page.getList());
        return map;
    }

    @Override
    public void deleteEmp(String e_id) {
        testDao.deleteEmployee(e_id);
    }

    @Override
    public void deleteEmp(String[] eids) {
        if(eids==null || eids.length==0)return;
        testDao.deleteEmployees(eids);
    }
}
